package com.bt.controller.admin;

import com.bt.dto.YddArticleListDTO;
import com.bt.entity.YddArticle;
import com.bt.result.PageResult;
import com.bt.result.Result;
import com.bt.service.YddArticleService;
import com.bt.vo.YddArticlePageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author 青
 * @Date 2023-05-02 11:35
 */
@RequestMapping("/ydd_article")
@RestController
@Slf4j
@Api(tags = "文章管理")
public class YddArticleController {
    @Autowired
    YddArticleService yddArticleService;

    /**
     * 文章列表分页查询
     *
     * @param yddArticleListDTO
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("文章列表分页查询")
    public Result<PageResult> list(YddArticleListDTO yddArticleListDTO) {
        log.info("分页查询: {}", yddArticleListDTO);

        PageResult pageResult = yddArticleService.list(yddArticleListDTO);

        return Result.success(pageResult);
    }

    /**
     * 根据id删除文章
     *
     * @param id
     * @return
     */
    @GetMapping("/del")
    @ApiOperation("根据id删除文章")
    public Result del(Integer id) {
        yddArticleService.deleteById(id);
        return Result.success();
    }

    /**
     * 文章添加
     *
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("文章添加")
    public Result add(@RequestBody YddArticle yddArticle) {

        yddArticleService.add(yddArticle);

        return Result.success();
    }

    /**
     * 根据id查看文章详情(数据回显)
     *
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiOperation("根据id查看文章详情(数据回显)")
    public Result<YddArticle> rowInfo(String id) {
        YddArticle yddArticle = yddArticleService.rowInfo(id);

        return Result.success(yddArticle);
    }

    /**
     * 文章修改
     *
     * @param yddArticle
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("文章修改")
    public Result update(@RequestBody YddArticle yddArticle) {
        yddArticleService.update(yddArticle);

        return Result.success();
    }

}
